USE [Training]
GO

IF NOT EXISTS (SELECT * from dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.training_api_DepartmentTreeInsert'))
	EXEC('CREATE PROC dbo.training_api_DepartmentTreeInsert AS')
GO

ALTER PROC dbo.training_api_DepartmentTreeInsert
	@LocationID			int,
	@Parent				int = null,
	@Child				int = null,
	@DepartmentTreeID	int output
AS
	INSERT INTO DepartmentTree(
		LocationID,
		Parent,
		Child)
	VALUES(
		@LocationID,
		@Parent,
		@Child)
	SELECT @DepartmentTreeID = SCOPE_IDENTITY()
